home *** CD-ROM | disk | FTP | other *** search
- # include <types.h>
- # include <memory.h>
- # include <quickdraw.h>
- # include <toolutils.h>
- # include <windows.h>
- # include <dialogs.h>
- # include <menus.h>
- # include <textedit.h>
- # include <string.h>
- # include <files.h>
- # include <resources.h>
-
- # include <iac.h>
- # define PUBLIC extern
- # include <Editor.h>
-
- #define noErr 0 /* 0 for success */
-
- /**
- * Routine: Set Current Extent
- *
- * This is a local routine to set the fields in the 'current extent'
- * structure in the window data record. It is called by both hotCopy and
- * hotPaste routines, since by definitions the extents they define become
- * the 'current extent'.
- */
-
- # define __SEG__ Main
- void set_curr_ext(the_data_H, which)
- win_dataH the_data_H; /* data associated with the window */
- short which; /* # of extent which is now current */
- {
- extentH the_extH; /* handle to extent block */
- exTable ext_recs;
-
- the_extH = (**the_data_H).the_extents;
- ext_recs = *the_extH;
-
- curr_ext.src_doc = ext_recs[which].src_doc;
- curr_ext.hat_check = ext_recs[which].hat_check;
- curr_ext.ed_level = ext_recs[which].ed_level;
- curr_ext.ext_strt = ext_recs[which].ext_strt;
- curr_ext.ext_end = ext_recs[which].ext_end;
- }
-
-
- /**
- * Routine: do_hotCopy
- *
- * This routine is responsible for creating a new dependency source and
- * notifying the IAC driver. It is called primarily by the "source" program.
- */
-
- # define __SEG__ Main
- void do_hotCopy()
-
- {
- win_dataH the_data_H; /* data associated with a window */
- TEHandle TextH; /* The TextEdit handle */
- extentH the_extH; /* handle to extent block */
- exTable ext_recs;
- long the_doc; /* local copies due to memory mashing */
- short slot_ID, h_check, the_ed;
- short e_cnt;
- short item_hit; /* error processing */
- Str255 err_str, str2;
-
- short iac_err = noErr;
- Boolean in_extent = false;
-
- extern Boolean chk_extent(); /* sets "current extent" if found */
- extern void add_display_cmd(); /* update 'Links' menu */
- extern void set_curr_ext(); /* update global structure */
-
- extern Boolean ext_active;
-
- the_data_H = (win_dataH) GetWRefCon (myWindow);
- the_extH = (**the_data_H).the_extents;
- TextH = (**the_data_H).wind_TEH;
- the_doc = (**the_data_H).doc_ID;
- slot_ID = (**the_data_H).the_slot;
- e_cnt = (**the_data_H).ext_cnt;
- h_check = 0;
-
- if (!chk_extent(TextH, the_extH, (**the_data_H).ext_cnt))
- {
- iac_err = iac_add_dependency(&the_doc, &slot_ID, &h_check, &the_ed);
- if (iac_err == noErr)
- {
- SetHandleSize ((Handle)the_extH, sizeof(extent) * (e_cnt+1));
- ext_recs = *the_extH;
- ext_recs[e_cnt].hat_check = h_check;
- ext_recs[e_cnt].ed_level = the_ed;
- ext_recs[e_cnt].ext_strt = (**TextH).selStart;
- ext_recs[e_cnt].ext_end = (**TextH).selEnd;
- ext_recs[e_cnt].src_doc = the_doc;
- set_curr_ext(the_data_H,e_cnt);
-
- curr_ext_no = e_cnt;
- e_cnt += 1;
- (**the_data_H).doc_ID = the_doc; /* update window data */
- (**the_data_H).the_slot = slot_ID;
- (**the_data_H).ext_cnt = e_cnt;
- (**the_data_H).dirty = true; /* so we save extents */
- ext_active = true;
-
- iac_err = ext_write(TextH,
- (**TextH).selStart,
- ((**TextH).selEnd - (**TextH).selStart),
- the_doc,
- h_check,
- &the_ed);
-
- add_display_cmd(curr_ext_no, e_cnt); /* update menu */
- }
- else /* IAC alert here */
- {
- NumToString ((long)iac_err, &err_str);
- ParamText (&err_str, "Hot Copy", nil, nil);
- item_hit = StopAlert(IAC_ERR_ALRT, nil);
- }
- }
- else /* already-in-extent alert */
- {
- ParamText ("\"already-in-extent\"", "Hot Copy", nil, nil);
- item_hit = StopAlert(IAC_ERR_ALRT, nil);
- }
- }
-
-
- /**
- * Routine: do_hotPaste
- *
- * This routine is responsible for completing a new dependency and
- * notifying the IAC driver. It is called primarily by the "target" program.
- *
- * The dependencies are stored in the array in ascending sequence to make
- * updating simpler. See the header for poll_iac() for details.
- */
-
- # define __SEG__ Main
- void do_hotPaste()
-
- {
- win_dataH the_data_H; /* data associated with a window */
- TEHandle TextH; /* The TextEdit handle */
- extentH the_extH; /* handle to extent block */
- exTable ext_recs;
- long the_doc; /* local copies due to memory mashing */
- short slot_ID, h_check;
- short e_cnt, startt;
- short the_ed;
- short item_hit; /* error processing */
- Str255 err_str, str2;
-
- short i = 0;
- short iac_err = noErr;
- Boolean in_extent = false;
-
- extern Boolean chk_extent(); /* sets "current extent" if found */
- extern void add_display_cmd(); /* update 'Links' menu */
-
- extern Boolean ext_active;
-
- the_data_H = (win_dataH) GetWRefCon (myWindow);
- the_extH = (**the_data_H).the_extents;
- TextH = (**the_data_H).wind_TEH;
- slot_ID = (**the_data_H).the_slot;
- e_cnt = (**the_data_H).ext_cnt;
- the_doc = 0; /* just link to "available" */
- h_check = 0;
-
- if (!chk_extent(TextH, the_extH, e_cnt))
- {
- iac_err = iac_complete_dependency(&the_doc, &slot_ID, &h_check);
- if (iac_err == noErr) /* save "location" in TERec as extent */
- {
- (**the_data_H).the_slot = slot_ID; /* update window data */
- ext_active = true;
- startt = (**TextH).selStart;
- SetHandleSize ((Handle)the_extH, sizeof(extent) * (e_cnt+1));
-
- /* walk extent table to find entry to insert BEFORE */
- ext_recs = *the_extH;
- while (i<e_cnt)
- {
- if ( (ext_recs[i].ext_strt==0) /* at end of table */
- || (ext_recs[i].ext_strt>startt) ) /* table entry bigger */
- {
- /* move tail of table to make space */
- BlockMove(&ext_recs[i],
- &ext_recs[i+1],
- (e_cnt - i) * sizeof(extent));
- break;
- }
- else
- {
- i += 1;
- }
- }
-
- ext_recs[i].hat_check = h_check; /* fill in table entry */
- ext_recs[i].ext_strt = (**TextH).selStart;
- ext_recs[i].ext_end = (**TextH).selEnd;
- ext_recs[i].src_doc = the_doc;
- set_curr_ext(the_data_H,i);
-
- /* now read data from newly connected link */
- the_ed = 0;
- iac_err = ext_read(myWindow, &the_ed, i);
-
- extent_count += 1; /* global count */
- curr_ext_no = i;
- (**the_data_H).ext_cnt = e_cnt + 1;
- (**the_data_H).dirty = true;
- add_display_cmd(i, extent_count); /* update menu */
-
- }
- else
- {
- NumToString ((long)iac_err, &err_str);
- ParamText (&err_str, "Hot Paste", nil, nil);
- item_hit = StopAlert(IAC_ERR_ALRT, nil);
- }
- }
- else /* already-in-extent alert */
- {
- ParamText ("\"already-in-extent\"", "Hot Paste", nil, nil);
- item_hit = StopAlert(IAC_ERR_ALRT, nil);
- }
- }
-